// 用户相关api
import request from '@/utils/request'
import { getStorage } from '@/utils/storage'
// 获取用户信息
export const getUserInfoApi = () => {
  return request({
    url: '/v1_0/user'
  })
}

// 获取个人资料(包含生日)
export const getProfileApi = () => {
  return request({
    url: '/v1_0/user/profile'
  })
}

// 上传头像
export const uploadImgeApi = (fd) => {
  return request({
    url: '/v1_0/user/photo',
    method: 'PATCH',
    data: fd
  })
}
// 编辑用户资料(更新)
// export const editUserInApi = ({
//   name = null,
//   birthday = null,
//   gender = null,
//   real_name = null,
//   into = null
// }) => {
//   // 自己先判断是否有参数传入
//   const obj = {}
//   if (name !== null) {
//     obj.name = name
//   }
//   if (birthday !== null) {
//     obj.name = birthday
//   }
//   if (gender !== null) {
//     obj.name = gender
//   }
//   if (real_name !== null) {
//     obj.name = real_name
//   }
//   if (into !== null) {
//     obj.name = into
//   }
//   return request({
//     url: '/v1_0/user/profile',
//     method: 'PATCH',
//     data: obj
//   })
// }

// 编辑用户资料(更新)
export const editUserInApi = ({
  name,
  birthday,
  gender,
  real_name,
  into
}) => {
  // 后台自动判断有没有参数传入
  return request({
    url: '/v1_0/user/profile',
    method: 'PATCH',
    data: {
      name,
      birthday,
      gender,
      real_name,
      into
    }
  })
}

// 刷新token
export const refreshTokenApi = () => {
  return request({
    url: '/v1_0/authorizations',
    method: 'PUT',
    headers: {
      Authorization: `Bearer ${getStorage('refresh_token')}`
    }
  })
}
